#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

import abc

from common.common import output_result_file

from adds.comm.log import log


class ADDSServiceBase(metaclass=abc.ABCMeta):
    def __init__(self, req_id: str, job_id: str, sub_id: str):
        self.req_id = req_id
        self.job_id = job_id
        self.sub_id = sub_id

    def report_result(self, result_info):
        """
        功能描述：上报任务执行结果
        参数：
        @result_info： dict
        返回值：无
        """
        log.info(f"Write result to file, req_id: {self.req_id}")
        try:
            output_result_file(self.req_id, result_info)
        except Exception as e:
            log.error(f"Report job result failed! reason: {str(e)}")
